﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Duality;
using Duality.Resources;
using OpenTK;

namespace PhoenixCrab.Cameras
{
    [Serializable]
    public class StayWithCamera:Component,ICmpUpdatable, ICmpInitializable
    {

        public Vector2 CameraRelativePosition { get; set; }


        public void OnUpdate()
        {
            var cp = Scene.Current.Cameras.ElementAt(0).GameObj.Transform.Pos.Xy;

            GameObj.Transform.Pos = new Vector3(CameraRelativePosition + cp, GameObj.Transform.Pos.Z);
        }

        public void OnInit(InitContext context)
        {
            if (context == InitContext.AddToGameObject)
            {
                CameraRelativePosition = GameObj.Transform.Pos.Xy;
            }
        }

        public void OnShutdown(ShutdownContext context)
        {
            
        }
    }
}
